﻿<UserControl x:Class="Agnes.TaskManager.TaskSummaryView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:ext="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
             xmlns:local="clr-namespace:Agnes.TaskManager"
             xmlns:dxsch="http://schemas.devexpress.com/winfx/2008/xaml/scheduler"
             xmlns:core="clr-namespace:Agnes.Core;assembly=Agnes.Core"
             xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
             xmlns:cal="http://www.caliburnproject.org"
             xmlns:XtraScheduler="clr-namespace:DevExpress.XtraScheduler;assembly=DevExpress.XtraScheduler.v11.2.Core"
             FontSize="13" FontFamily="SimSun"  
             d:DesignHeight="191" d:DesignWidth="882">
    <UserControl.Resources>
        <local:StatusTypeToColorConvter x:Key="StatusToColorConvter" />
        <local:TaskStatusToAppointmentStatusConverter x:Key="StatusConvter"/>
        <local:TaskDataContext x:Key="TaskDataContext" />
        <local:IntToLabelConverter x:Key="LabelConvter" />
        <local:StatusTypeToStringConverter x:Key="StatusToStringConvter" />
        <core:FalseToCollapsedConverter x:Key="FalseToCollapsedConvter" />
        <core:TrueToCollapsedConverter x:Key="TrueToCollapsedConvter" />
        <core:FalseToTrueConverter x:Key="FalseToTrueConvter" />
        <core:DateTimeToStringConverter x:Key="DateTimeConvter" />
    </UserControl.Resources>

    <Grid>
        <Grid.Resources>
            <ResourceDictionary>
                <Style x:Key="progressBarStyle" TargetType="ProgressBar">
                    <Style.Setters>
                        <Setter Property="Minimum" Value="0" />
                        <Setter Property="Maximum" Value="100" />
                        <Setter Property="Value" Value="{Binding Row.Progress}" />
                        <Setter Property="Height" Value="8" />
                        <Setter Property="Foreground" Value="#00DA00" />
                        <Setter Property="BorderThickness" Value="0" />
                        <Setter Property="Padding" Value="0" />
                    </Style.Setters>
                </Style>

                <DataTemplate x:Key="progressableTemplate">
                    <dx:MeasurePixelSnapper>
                        <StackPanel Orientation="Vertical" Background="Transparent">
                            <ContentPresenter x:Name="defaultRowPresenter" Content="{Binding}" ContentTemplate="{Binding View.DefaultDataRowTemplate}" />
                            <Border HorizontalAlignment="Stretch" VerticalAlignment="Center" BorderThickness="0,1,0,0"
                                    BorderBrush="{Binding ElementName=PART_DataRow, Path=BorderBrush}">
                                <ProgressBar 
                                             Style="{StaticResource progressBarStyle}" />
                            </Border>
                        </StackPanel>
                    </dx:MeasurePixelSnapper>
                </DataTemplate>

                <local:TaskDataTemplateSelector x:Key="selector">
                    <local:TaskDataTemplateSelector.TaskDataTemplate>
                        <DataTemplate  DataType="{x:Type local:Task}">
                            <ContentControl x:Name="defaultRowPresenter" Content="{Binding}" ContentTemplate="{Binding ElementName=TLCView, Path=DefaultDataRowTemplate}" />
                        </DataTemplate>
                    </local:TaskDataTemplateSelector.TaskDataTemplate>
                    <local:TaskDataTemplateSelector.TaskSammaryDataTemplate>
                        <HierarchicalDataTemplate DataType="{x:Type local:Task}" ItemsSource="{Binding Path=Childs}">
                            <StackPanel >
                                <ContentPresenter Loaded="TaskCatagoryLoaded" x:Name="defaultRowPresenter" Content="{Binding}"
                                                ContentTemplate="{Binding ElementName=TLCView, Path=DefaultDataRowTemplate}" >
                                </ContentPresenter>
                                <ProgressBar Style="{StaticResource progressBarStyle}" Height="5" Foreground="#00DA00"/>
                            </StackPanel>
                        </HierarchicalDataTemplate>
                    </local:TaskDataTemplateSelector.TaskSammaryDataTemplate>
                </local:TaskDataTemplateSelector>
            </ResourceDictionary>
        </Grid.Resources>

        <dxg:TreeListControl x:Name="TLC" ItemsSource="{Binding Model.Roots}" Background="LightBlue" FontSize="13">
            <dxg:TreeListControl.Columns>
                <dxg:TreeListColumn Width="0"/>
                <dxg:TreeListColumn Width="15">
                    <dxg:TreeListColumn.CellTemplate>
                        <DataTemplate>
                            <Border Width="15" Background="{Binding RowData.Row.TaskStatus, Converter={StaticResource StatusToColorConvter}}" />
                        </DataTemplate>
                    </dxg:TreeListColumn.CellTemplate>
                </dxg:TreeListColumn >
                <dxg:TreeListColumn Name="Subject" Header="主题" FieldName="Subject" Width="150" >
                    <dxg:TreeListColumn.CellTemplate>
                        <DataTemplate>
                            <dxe:TextEdit x:Name="PART_Editor"  IsEnabled="{Binding RowData.Row.IsTaskCatagory, Converter={StaticResource FalseToTrueConvter}}" />
                        </DataTemplate>
                    </dxg:TreeListColumn.CellTemplate>
                </dxg:TreeListColumn>
                <dxg:TreeListColumn  Header="类别" FieldName="Label" Width="100" >
                    <dxg:TreeListColumn.CellTemplate>
                        <DataTemplate>
                            <dxsch:AppointmentLabelEdit Margin="1"
                                                        Storage="{Binding Source={StaticResource TaskDataContext}, Path=SchedulerStorage}"
                                                        SelectedItem="{Binding RowData.Row.LabelId, Converter={StaticResource LabelConvter}, Mode=TwoWay}"/>
                        </DataTemplate>
                    </dxg:TreeListColumn.CellTemplate>
                </dxg:TreeListColumn>
                <dxg:TreeListColumn Name="Start" Header="开始时间" Width="130" FieldName="StartDT">
                    <dxg:TreeListColumn.CellTemplate>
                        <DataTemplate>
                            <dxe:DateEdit x:Name="PART_Editor" IsEnabled="{Binding RowData.Row.IsTaskCatagory, Converter={StaticResource FalseToTrueConvter}}" 
                                          Mask="yyyy/MM/dd HH:mm" DisplayFormatString="yyyy/MM/dd HH:mm" />
                        </DataTemplate>
                    </dxg:TreeListColumn.CellTemplate>
                </dxg:TreeListColumn>
                <dxg:TreeListColumn Name="End" FieldName="EndDT" Header="结束时间" Width="130">
                    <dxg:TreeListColumn.CellTemplate>
                        <DataTemplate>
                            <dxe:DateEdit x:Name="PART_Editor" IsEnabled="{Binding RowData.Row.IsTaskCatagory, Converter={StaticResource FalseToTrueConvter}}" 
                                          Mask="yyyy/MM/dd HH:mm" DisplayFormatString="yyyy/MM/dd HH:mm"/>
                        </DataTemplate>
                    </dxg:TreeListColumn.CellTemplate>
                </dxg:TreeListColumn>
                <dxg:TreeListColumn Name="Progress" Header="完成率" FieldName="Progress" Width="60">
                    <dxg:TreeListColumn.CellTemplate>
                        <DataTemplate>
                            <dxe:SpinEdit x:Name="PART_Editor" MinValue="0" MaxValue="100" 
                                          IsEnabled="{Binding RowData.Row.IsTaskCatagory, Converter={StaticResource FalseToTrueConvter}}" />
                        </DataTemplate>
                    </dxg:TreeListColumn.CellTemplate>
                </dxg:TreeListColumn>
                <dxg:TreeListColumn Name="Status" Header="状态" >
                    <dxg:TreeListColumn.CellTemplate>
                        <DataTemplate>
                            <Grid Margin="1">
                                <dxsch:AppointmentStatusEdit Storage="{Binding Source={StaticResource TaskDataContext}, Path=SchedulerStorage}"
                                                             SelectedItem="{Binding RowData.Row.TaskStatus, Converter={StaticResource StatusConvter}, Mode=TwoWay}"
                                                             IsEnabled="{Binding RowData.Row.IsTaskCatagory, Converter={StaticResource FalseToTrueConvter}}"  
                                                             Visibility="{Binding RowData.IsFocused, Converter={StaticResource FalseToCollapsedConvter}}"/>
                                <TextBlock Visibility="{Binding RowData.IsFocused, Converter={StaticResource TrueToCollapsedConvter}}"
                                           Margin="5,2"
                                           TextAlignment="Center" HorizontalAlignment="Left" 
                                           Text="{Binding RowData.Row.TaskStatus, Converter={StaticResource StatusToStringConvter}}" />
                            </Grid>
                        </DataTemplate>
                    </dxg:TreeListColumn.CellTemplate>
                </dxg:TreeListColumn>
                <dxg:TreeListColumn Name="Description" Header="备注" FieldName="Description" />
            </dxg:TreeListControl.Columns>
            <dxg:TreeListControl.View>
                <dxg:TreeListView x:Name="TLCView" 
                                  SelectedRowsSource="{Binding Path=SelectedRows}"
                                  TreeDerivationMode="HierarchicalDataTemplate" 
                                  MultiSelectMode="Row"
                                  AutoExpandAllNodes="True"
                                  cal:Message.Attach="[Event CellValueChanged]=[Action DataChanged()]"
                                  AllowBestFit="False"
                                  ShowVerticalLines="True"
                                  ShowHorizontalLines="True"
                                  ShowIndicator="False"
                                  RowMinHeight="22"
                                  DataRowTemplateSelector="{StaticResource selector}"
                                  >
                    <dxg:TreeListView.RowStyle>
                        <Style>
                            <Style.Resources>
                                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                            </Style.Resources>
                        </Style>
                    </dxg:TreeListView.RowStyle>
                </dxg:TreeListView>
            </dxg:TreeListControl.View>
        </dxg:TreeListControl>
    </Grid>
</UserControl>
